//
//  XLWelcomeController.swift
//  微博
//
//  Created by macbook on 16/9/30.
//  Copyright © 2016年 buWangChuXing. All rights reserved.
//

import UIKit
import SDWebImage

class XLWelcomeController: UIViewController {
    
    override func loadView() {
        
       view = backImageView
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupUI()
    }
    
    
    
    
    
    
    //懒加载
    private lazy var backImageView : UIImageView = UIImageView(imageName: "ad_background")
    
    //头像
    private lazy var iconImageView : UIImageView = {
    
        
        let icon = UIImageView(imageName:"avatar_default_big")
        icon.layer.borderColor = ThemeColor.CGColor
        icon.layer.borderWidth = 3
        icon.layer.cornerRadius = 45;
        icon.layer.masksToBounds = true
        //设置图片
        icon.sd_setImageWithURL(NSURL(string:XLUserAccountTools.shardTools.userAccount?.avatar_large ?? ""), placeholderImage: UIImage(named: "ad_background"))
        
        return icon
    }()
    
    //文字
    private lazy var messageLabel : UILabel = {
    
        let lab = UILabel()
        lab.text = "欢迎回来"
        lab.font = UIFont.systemFontOfSize(20)
        lab.textColor = UIColor.grayColor()
        lab.textAlignment  = .Center
        lab.alpha = 0

        return lab
    }()
    
    //更改约束
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        //更改头像约束
        self.iconImageView.snp_makeConstraints { (make) in
            
            make.top.equalTo(self.view).offset(100)
        }
        
        UIView.animateWithDuration(3, delay: 1, usingSpringWithDamping: 0.6, initialSpringVelocity: 0, options: [], animations: { 
            //如果更改约束需要修改当前frame
            self.view.layoutIfNeeded()
            }) { (_) in
                
                UIView.animateWithDuration(0.25, animations: {
                    self.messageLabel.alpha = 1
                })
        }
        
    }
    
    func setupUI(){
        
        view.addSubview(iconImageView)
        view.addSubview(messageLabel)
        
        iconImageView.snp_makeConstraints { (make) in
            
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.top.equalTo(view).offset(400)
            make.centerX.equalTo(view)
            
        }
        
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(view)
            make.top.equalTo(iconImageView.snp_bottom).offset(16)
        }
        
        
    }

    
    

}























